programming4us
           
 
 
Programming

Microsoft Visual Studio 2010 : Reports and Debugging - Using the Parallel Tasks Window

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
7/8/2013 3:45:04 AM

Tasks, tasks, and more tasks! Parallel programs are built upon tasks. In the TPL, tasks are wrappers for parallel operations that are later queued and scheduled on threads in the .NET Framework 4 thread pool, which is the default scheduler. As such, tasks are the central ingredient of a parallel program; tasks replace threads as the basic unit of execution. Tasks are part of the additional complexity found in parallel code. For these reasons, debugging a parallel application often begins with debugging tasks.

Visual Studio 2010 introduces the Parallel Tasks window for monitoring and debugging tasks. The Parallel Tasks window is similar to the Threads window in its look and feel and functionality. For those familiar with the Threads window, transitioning to the Parallel Tasks window should be simple. The next image shows the Parallel Tasks window.

Using the Parallel Tasks Window

The Parallel Tasks window displays several columns. Some of these columns are identical to those in the Threads window:

  • First column (no heading) . You can flag a task in the first column. Flagging is used to group, highlight, or filter tasks.

  • Second column (no heading) . This is the active task column. A yellow arrow indicates the current task. If a white arrow appears in this column, it indicates the task that has been interrupted by the debugger.

  • ID . The ID is the task identifier.

  • Status . Status is the execution state of the task, such as running, waiting, or deadlocked. The appropriate icon is displayed at the left end of the column.

  • Location . This column shows the location of the task in the call stack. If you point to an entry in this column, the entire call stack for the task is displayed. The entry point method for the task is displayed at the bottom of the call stack (see the next image).

  • Task . This is the entry point method and argument for the task.

  • Thread Assignment . Tasks run on threads. This column displays the name and thread identifier of that thread.

  • AppDomain . This identifies the application domain for the task.

AppDomain

Click a column heading to sort on that column, or drag a column heading to change the column order. You can use the context menu to select additional columns, such as the Task and AppDomain columns. You can also group tasks on a particular column. Choose Group By ColumnName from the context menu. In the following image, the tasks are grouped by status.

AppDomain

Developers often struggle to resolve deadlock conditions. Here, the Parallel Tasks window comes to the rescue! In this example, both Task 2 and Task 3 are deadlocked on something. What is the reason for the deadlock? In the next exercise, you will discover the answer to that question.

Use the Parallel Tasks window to find the source of a deadlock

  1. If you have not done so already, create a console application for Microsoft Visual C# in Visual Studio 2010.

  2. Build the application and start debugging. A breakpoint instruction is programmatically embedded in the application. The program will automatically break at the hardcoded breakpoint.

  3. From the Debug menu, choose Windows. Open the Parallel Tasks window. Use the context menu, as shown earlier, to group tasks on the Status column.

  4. Now that the columns are grouped by status, you can easily observe that Task 2 and Task 3 are deadlocked. Point to the status column for Task 2. As shown in the following image, a tooltip is displayed that indicates that Task 2 is waiting for a System.Object owned by thread 7992. Upon examining the call stack, you see that Task 3 is running on that thread.

    Note

    The task and thread numbers might vary on your machine.

    AppDomain
  5. Point to the status for Task 3. Once again, you’ll see a tooltip. Task 3 is also blocked and waiting for a System.Object. This object is owned by thread 4780.

    AppDomain
  6. Evidence points to a deadlock because Task 2 and Task 3 are both blocked and waiting for each other. You can examine the source code to confirm this. In the Parallel Tasks window, open the context menu for Task 3. Select Switch To Task. This will jump to the actual source code for that task (see the next image). The final statement executed for the current stack frame is highlighted, which is the Monitor.Enter method on the s2 object as a parameter. This is where the task deadlocked. You should note that the task has already acquired a lock for the s1 object.

    AppDomain
  7. Repeat the steps for Task 2 to view the source code (see the following image). You should see that this task has stopped on a Monitor.Enter method for the s1 object, which is the same object that Task 3 already owns. Aha! This confirms that Task 2 and Task 3 are hopelessly deadlocked on each other. Admittedly this example is somewhat contrived. However, it demonstrates many of the features of the new Parallel Tasks window.

    AppDomain
Other -----------------
- Microsoft Visual Studio 2010 : Debugging with Visual Studio 2010 (part 2) - Debugging Threads
- Microsoft Visual Studio 2010 : Debugging with Visual Studio 2010 (part 1) - Live Debugging, Performing Post-Mortem Analysis
- .NET Components : Serialization and Class Hierarchies (part 2) - Manual Base-Class Serialization
- .NET Components : Serialization and Class Hierarchies (part 1) - Custom Serialization and Base Classes
- .NET Components : Custom Serialization (part 2) - Constraining Serialization
- .NET Components : Custom Serialization (part 1) - The ISerializable Interface, Implementing ISerializable
- .NET Components : Serialization and Streams - Serializing Multiple Objects
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 5) - Advanced HTTP Handler Programming
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 4) - Serving Images More Effectively
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 3) - The Picture Viewer Handler
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 2) - An HTTP Handler for Quick Data Reports
- Microsoft ASP.NET 3.5 : Writing HTTP Handlers (part 1) - The IHttpHandler Interface
- Microsoft ASP.NET 3.5 : HTTP Handlers and Modules - Quick Overview of the IIS Extensibility API
- Programming WCF Services : Queued Services - The HTTP Bridge
- Microsoft ASP.NET 4 : Ajax - Extender Controls (part 2) - A Modal Pop-up Dialog-Style Component
- Microsoft ASP.NET 4 : Ajax - Extender Controls (part 1) - The AutoComplete Extender
- Mobile Handheld Devices : DATA SYNCHRONIZATION
- Mobile Handheld Devices : MEMORY, STORAGE AND BATTERIES
- LINQ to Objects : How to Return Elements When the Result Is a Sequence (Select Many)
- LINQ to Objects : How to Change the Return Type (Select Projection)
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us